flutter date input field

61

dependencies:				// in pubspec.yaml 
   date_field: ^0.1.2
   
DateTime selectedData;
return DateField(    		// in a build
	onDateSelected: (DateTime value) {
    	setState(() { selectedData = value; });
	},
	selectedDate: selectedData,  
);
void _selectDate(){
    showDatePicker(
      context: context,
      initialDate: selectedDate,
      firstDate: DateTime(1950),
      lastDate: DateTime.now(),
    ).then((pickedDate) {
      if (pickedDate == null) {
        return;
      }

      setState(() {
        selectedDate = pickedDate;
        dateValue.text = "${selectedDate.toLocal()}".split(' ')[0];
      });
    });
  }

Comments

Submit
0 Comments